﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Ultima.Xna.Graphics.UI.Gumps
{
    public class GumpTiledImage : GumpEntry
    {
        private Texture2D _texture;
        private int _hue;
        private int _gumpId;
        private bool _dirty;

        internal Texture2D Texture
        {
            get { return _texture; }
            set { _texture = value; }
        }

        public int Hue
        {
            get { return _hue; }
            set
            {
                _hue = value;
                _dirty = true;
            }
        }

        public int GumpId
        {
            get { return _gumpId; }
            set
            {
                _gumpId = value;
                _dirty = true;
            }
        }

        public override Vector2 Size
        {
            get
            {
                if (_texture == null)
                    return base.Size;

                return new Vector2(_texture.Width, _texture.Height);
            }
            set
            {
                base.Size = value;
            }
        }

        public GumpTiledImage(Game game)
            : base(game)
        {
            MovesParent = true;
        }

        public override void Initialize()
        {
            base.Initialize();

            _dirty = false;
            _texture = Data.Gumps.CreateTexture(Game.GraphicsDevice, _gumpId);
        }

        public override void Draw(GameTime gameTime)
        {
            if (_dirty)
            {
                _dirty = false;
                _texture = Data.Gumps.CreateTexture(Game.GraphicsDevice, _gumpId);
            }

            //GumpEffect.Parameters["HueTexture"].SetValue(Hues.Texture);
            //GumpEffect.Parameters["Hue"].SetValue(new Vector2(Hue - 1, 0));

            //Manager.SpriteBatch.End();

            //Manager.SpriteBatch.Shader = GumpEffect;
            //Manager.SpriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate, SaveStateMode.None);

            //Manager.SpriteBatch.Draw(_texture, Bounds, Bounds Color.White);

            //Manager.SpriteBatch.End(true);

            ////Restart the spritebatch 
            //Manager.SpriteBatch.Begin();

            base.Draw(gameTime);
        }
    }
}
